package com.weavernorth.action.application;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;


/**
 * 请假流程控制
 */
public class LeaveToHrAction implements Action {
    private static Log log = LogFactory.getLog(LeaveToHrAction.class);

    @Override
    public String execute(RequestInfo requestInfo) {
        BaseBean bb = new BaseBean();
        RecordSet rsDetail = new RecordSet();

        //获取请求ID
        String strLcId = requestInfo.getRequestid();
        //获取表单名称
     //   String strTableName = requestInfo.getRequestManager().getBillTableName();
        RecordSet rsTable=new RecordSet();
        String strTableName ="";
        rsTable.execute("select tablename  from workflow_bill where id = (select formid from workflow_base where id=(select workflowid from workflow_requestbase  where requestid='"+strLcId+"') and isbill=1)");
        if(rsTable.next()){
            strTableName=rsTable.getString("tablename");
        }
      log.info("tablename的值是：" + strTableName);

        //查询明细表数据的sql
        String strSqlDetail = "select * from " + strTableName + "_dt1 d," + strTableName + " s  where d.mainid=s.id  and  s.requestid = '" + strLcId + "' and d.detail_duration>'5'";
        log.info("查询明细表数据的sql：" + strSqlDetail);
        rsDetail.executeQuery(strSqlDetail);
        String strHr = "1";
        if (rsDetail.next()) {
            //如果存在更新是否需要hr审批字段
            strHr = "0";
        }
        String strUpsql = "update " + strTableName + " set sfxhrsp='" + strHr + "' where requestid=?";
        log.info("更新是否需要hr审批字段:" + strUpsql + ",requestid:" + strLcId);
        rsDetail.executeUpdate(strUpsql, strLcId);
        return SUCCESS;

    }
}